home *** CD-ROM | disk | FTP | other *** search
- // VCTCImage.cpp : Implementation of CVCTCImage
- #include "stdafx.h"
- #include "VCTCImageTool.h"
- #include "VCTCImage.h"
- #include "xdbtool_i.c"
- #include "gxties_i.c"
- #include "imsigx_i.c"
- #include "tcimage.h"
-
-
- COleVariant t(-1L, VT_BOOL);
- COleVariant f(0L, VT_BOOL);
- COleVariant missing((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
-
- /////////////////////////////////////////////////////////////////////////////
- // CVCTCImage
- STDMETHODIMP CVCTCImage::get_ClassID(BSTR *pVal)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState())
- HRESULT hRes = E_FAIL;
- LPOLESTR olestr = NULL;
-
- try
- {
- if(SUCCEEDED( ::StringFromCLSID(CLSID_VCTCImage, &olestr)))
- {
- *pVal = ::SysAllocString(olestr);
- hRes = S_OK;
- }
- }
- catch (...)
- {
- TRACE_EXCEPTION("CVCTCImage::get_ClassID")
- }
-
- if (olestr != NULL)
- CoTaskMemFree(olestr);
-
- return hRes;
- }
-
- STDMETHODIMP CVCTCImage::get_Description(BSTR *pVal)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState())
-
- HRESULT hRes = E_FAIL;
- // Get the description from the resource
- CString strResult;
- if (strResult.LoadString(IDS_DESCRIPTION))
- {
- hRes = S_OK;
- *pVal = strResult.AllocSysString();
- }
- return hRes;
- }
-
- STDMETHODIMP CVCTCImage::GetToolInfo(VARIANT *CommandNames, VARIANT *MenuCaptions, VARIANT *StatusPrompts, VARIANT *ToolTips, VARIANT *Enabled, VARIANT *WantsUpdates, long *ret)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState())
- HRESULT hRes = E_FAIL;
-
- SAFEARRAYBOUND bound = {NUM_TOOLS, 0};
- SAFEARRAYBOUND bound1[2] = {{NUM_TOOLS, 0}, {2, 0}};
-
- CString cstrText;
- CString cstrTextTemp;
-
- BSTR bstrCommandName = NULL;
- BSTR bstrMenuCaption = NULL;
- BSTR bstrStatusPrompt = NULL;
- BSTR bstrToolTip = NULL;
- BOOL bEnabled = TRUE;
- BOOL bWantsUpdates = TRUE;
-
-
- long lIndicies = 0;
- long lIndicies1[2];
- lIndicies1[0] = 0;
- lIndicies1[1] = 0;
- try
- {
-
- hRes = SafeArrayRedim(CommandNames->parray, &bound);
- CHECK_HRESULT(hRes)
-
- MenuCaptions->parray = SafeArrayCreate(VT_BSTR, 2, bound1);
-
- hRes = SafeArrayRedim(StatusPrompts->parray, &bound);
- CHECK_HRESULT(hRes)
-
- hRes = SafeArrayRedim(ToolTips->parray, &bound);
- CHECK_HRESULT(hRes)
-
- hRes = SafeArrayRedim(Enabled->parray, &bound);
- CHECK_HRESULT(hRes)
-
- hRes = SafeArrayRedim(WantsUpdates->parray, &bound);
- CHECK_HRESULT(hRes)
-
- cstrText.LoadString (IDS_MAINMENU);
- cstrText.Insert(cstrText.GetLength (), '|');
- cstrTextTemp.LoadString (IDS_SUBMENU);
- cstrText.Insert(cstrText.GetLength (), cstrTextTemp);
- cstrText.Insert(cstrText.GetLength (), '|');
- cstrTextTemp.LoadString (IDS_MENUCAPTION);
- cstrText.Insert(cstrText.GetLength (), cstrTextTemp);
- cstrTextTemp.Empty ();
-
- cstrText += "#CMD_SDKINSERTFILE";
-
- bstrCommandName = cstrText.AllocSysString();
- hRes = SafeArrayPutElement(CommandNames->parray, &lIndicies, (void *)bstrCommandName);
- CHECK_HRESULT(hRes)
-
- cstrText.Empty ();
- cstrText.LoadString (IDS_MENUCAPTION);
- bstrMenuCaption = cstrText.AllocSysString();
- hRes = SafeArrayPutElement(MenuCaptions->parray, lIndicies1, (void *)bstrMenuCaption);
- CHECK_HRESULT(hRes)
- cstrText.Empty ();
-
- // cstrText.LoadString (IDS_PROMT0);
- // bstrStatusPrompt = cstrText.AllocSysString();
- // hRes = SafeArrayPutElement(StatusPrompts->parray, &lIndicies, (void *)bstrStatusPrompt);
- // CHECK_HRESULT(hRes)
- // cstrText.Empty ();
-
- cstrText.LoadString (IDS_TOOLTIPS);;
- bstrToolTip = cstrText.AllocSysString();
- hRes = SafeArrayPutElement(ToolTips->parray, &lIndicies, (void *)bstrToolTip);
- CHECK_HRESULT(hRes)
-
- hRes = SafeArrayPutElement(Enabled->parray, &lIndicies, (void *)&bEnabled);
- CHECK_HRESULT(hRes)
-
- hRes = SafeArrayPutElement(WantsUpdates->parray, &lIndicies, (void *)&bWantsUpdates);
- CHECK_HRESULT(hRes)
-
- // put default toolbar name
- lIndicies1[0] = 0;
- lIndicies1[1] = 1;
-
- cstrText.LoadString (IDS_TOOLBAR_NAME);
- bstrMenuCaption = cstrText.AllocSysString();
-
- hRes = SafeArrayPutElement(MenuCaptions->parray, lIndicies1, (void *)bstrMenuCaption);
- CHECK_HRESULT(hRes)
- cstrText.Empty ();
-
- *ret = NUM_TOOLS;
- }
- catch (...)
- {
- if (SUCCEEDED(hRes))
- hRes = E_FAIL;
- TRACE_EXCEPTION("CVCTCImage::GetToolInfo")
- }
- return hRes;
- }
-
- STDMETHODIMP CVCTCImage::CopyBitmap(VARIANT_BOOL LargeButtons, VARIANT_BOOL Monochrome, VARIANT_BOOL *ret)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState())
-
- // TODO: Add your implementation code here
-
- return S_OK;
- }
-
-
- STDMETHODIMP CVCTCImage::GetPicture(VARIANT_BOOL LargeButtons, VARIANT_BOOL Monochrome, IDispatch **ret)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState())
- LPTSTR IDB = 0;
-
- HRESULT hRes = E_FAIL;
- try
- {
- if(LargeButtons)
- {
- IDB = MAKEINTRESOURCE(IDB_BMP2);
- }
- else
- {
- IDB = MAKEINTRESOURCE(IDB_BMP1);
- }
- HBITMAP pBmp = ::LoadBitmap(AfxGetResourceHandle(), IDB);
-
- PICTDESC pict;
- pict.cbSizeofstruct = sizeof(pict);
- pict.picType = PICTYPE_BITMAP;
- pict.bmp.hbitmap = pBmp;
- pict.bmp.hpal = NULL;
-
- hRes = OleCreatePictureIndirect(&pict, IID_IDispatch, TRUE, (void**)ret);
-
- CHECK_HRESULT(hRes)
- hRes = S_OK;
- }
- catch (...)
- {
- TRACE_EXCEPTION("CVCTCImage::GetPicture")
- }
-
- return S_OK;
- }
- void InsertImage(CString sImageFilePath, IDrawing *pDrawing)
- {
- ITCImageManager pImageManager;
- COleException oerr;
- CString sname("Test name");
- IMatrix* pMatrix = NULL;
- double dx = 100;
- double dy = 100;
- BOOL bReference = TRUE;
- pImageManager.CreateDispatch("TCImage.TCImageManager",&oerr);
- long lImageStyle = pImageManager.AddImageStyle(pDrawing, sname, sImageFilePath, bReference);
-
- HRESULT hRes = pDrawing->get_UCS(&pMatrix);
- IGraphic* pGraphic = (IGraphic*)pImageManager.CreateImageObject(pDrawing, lImageStyle, pMatrix, dx, dy);
- Properties* pProps = NULL;;
- Property* pProp = NULL;
- hRes = pGraphic->get_Properties(&pProps);
- COleVariant varIndex("%#$AUX@_ShowImage");
- COleVariant varValue(1L);
- hRes = pProps->get_Item (&varIndex, &pProp);
- hRes = pProp->put_Value (1, &varValue);
- RELEASE(pMatrix);
- RELEASE(pProp);
- RELEASE(pProps);
- RELEASE(pGraphic);
- }
-
- STDMETHODIMP CVCTCImage::Run(IDispatch *ThisTool, VARIANT_BOOL *ret)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState())
- HRESULT hRes = E_FAIL;
- CString sExt = "Pictures (*.bmp;*.gif;*.jpg;*png;*.tif;*.pcx;*.ico;*.tga;*.wmf)|*.bmp;*.gif;*.jpg;*png;*.tif;*.pcx;*.ico;*.tga;*.wmf||";
-
-
- CFileDialog fDlg(TRUE, NULL, NULL,OFN_ENABLESIZING ,sExt, NULL);
- int res = fDlg.DoModal ();
- if (res != IDOK)
- {
- return S_OK;
- }
-
- CString strOutput = fDlg.GetPathName();
- CComPtr<IApplication> pApp;
- CComPtr<IDrawing> pActDr;
- CComPtr<View> pView;
- CComPtr<Tool> pTool;
- try
- {
- hRes = ThisTool->QueryInterface(IID_Tool, (void **)&pTool);
- CHECK_HRESULT(hRes)
- hRes = pTool->get_Application(&pApp);
- CHECK_HRESULT(hRes)
- hRes = pApp->get_ActiveDrawing(&pActDr);
- if (SUCCEEDED(hRes) && pActDr)
- {
- InsertImage(strOutput, pActDr);
- hRes = pActDr->get_ActiveView(&pView);
- CHECK_HRESULT(hRes);
- hRes = pView->ZoomToExtents();
- CHECK_HRESULT(hRes);
- }
-
- }
- catch(...)
- {
- TRACE_EXCEPTION("CVCTCImage::Run")
- }
- return S_OK;
- }
-
- STDMETHODIMP CVCTCImage::UpdateToolStatus(IDispatch *ThisTool, VARIANT_BOOL *Enabled, VARIANT_BOOL *Checked, VARIANT_BOOL *ret)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState())
- HRESULT hRes = E_FAIL;
-
- try
- {
- // do not allow to run this tool if it is already runned
- *ret = TRUE;
- hRes = S_OK;
-
- }
- catch (...)
- {
- TRACE_EXCEPTION("CVCTCImage::UpdateToolStatus")
- }
- return hRes;
- }
- STDMETHODIMP CVCTCImage::Initialize(IDispatch *ThisTool, VARIANT_BOOL *ret)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState())
- /*
- m_pIApplication = NULL;
- m_pITool = NULL;
- m_pTool = NULL;
- m_dwEventConnection = NULL;
- m_pDragGraphic = NULL;
- m_bDragging = FALSE;
- m_pTCADView = NULL;
- m_bInit = FALSE;
- m_pIToolEvents = NULL;
- */
- return S_OK;
- }
-
- STDMETHODIMP CVCTCImage::Terminate(IDispatch *ThisTool)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState())
-
- // TODO: Add your implementation code here
- return S_OK;
- }
-
-
-
-